// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.characters.IsoPlayer;
import zombie.commands.AltCommandArgs;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;

@CommandName(
    name = "invisible"
)
@AltCommandArgs({@CommandArgs(
        required = {"(.+)"},
        optional = "(-true|-false)"
    ), @CommandArgs(
        optional = "(-true|-false)"
    )})
@CommandHelp(
    helpText = "UI_ServerOptionDesc_Invisible"
)
@RequiredRight(
    requiredRights = 62
)
public class InvisibleCommand extends CommandBase {
    public InvisibleCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        String string0 = this.getExecutorUsername();
        String string1 = this.getCommandArg(Integer.valueOf(0));
        String string2 = this.getCommandArg(Integer.valueOf(1));
        if (this.getCommandArgsCount() == 2 || this.getCommandArgsCount() == 1 && !string1.equals("-true") && !string1.equals("-false")) {
            string0 = string1;
            if (this.connection.accessLevel == 2 && !string1.equals(this.getExecutorUsername())) {
                return "An Observer can only toggle invisible on himself";
            }
        }

        boolean boolean0 = false;
        boolean boolean1 = true;
        if ("-false".equals(string2)) {
            boolean1 = false;
            boolean0 = true;
        } else if ("-true".equals(string2)) {
            boolean0 = true;
        }

        IsoPlayer isoPlayer = GameServer.getPlayerByUserNameForCommand(string0);
        if (isoPlayer != null) {
            if (!boolean0) {
                boolean1 = !isoPlayer.isInvisible();
            }

            string0 = isoPlayer.getDisplayName();
            if (boolean0) {
                isoPlayer.setInvisible(boolean1);
            } else {
                isoPlayer.setInvisible(!isoPlayer.isInvisible());
                boolean1 = isoPlayer.isInvisible();
            }

            isoPlayer.setGhostMode(boolean1);
            GameServer.sendPlayerExtraInfo(isoPlayer, this.connection);
            if (boolean1) {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " enabled invisibility on " + string0);
                return "User " + string0 + " is now invisible.";
            } else {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " disabled invisibility on " + string0);
                return "User " + string0 + " is no more invisible.";
            }
        } else {
            return "User " + string0 + " not found.";
        }
    }
}
